package com.vitabuybuy.tv.ui.mine.order.adapter

import android.view.View
import androidx.recyclerview.widget.RecyclerView
import com.vitabuybuy.tv.R
import com.vitabuybuy.tv.databinding.ItemOrderGoodItemBinding
import com.vitabuybuy.tv.dto.OrderDetailDto
import com.library.common.base.BindRecycAdapter
import com.vitabuybuy.tv.ui.mine.order.OrderListActivity

class OrderGoodItemAdapter(val status: String) :
    BindRecycAdapter<ItemOrderGoodItemBinding, OrderDetailDto.ItemListBean>() {
    override fun onBindViewHolder(
        mBinding: ItemOrderGoodItemBinding,
        itemData: OrderDetailDto.ItemListBean,
        holder: RecyclerView.ViewHolder,
        position: Int
    ) {
        mBinding.itemData = itemData
        when (status) {
            OrderListActivity.WAITING_PAY -> {
                mBinding.btnCallShop.apply {
                    visibility = View.GONE
                }
            }
            OrderListActivity.WAITING_SEND -> {
                mBinding.btnCallShop.apply {
                    visibility = View.VISIBLE
                    isEnabled = !itemData.isIssue
                    text = if (itemData.isIssue) {
                        context.getString(R.string.aftersaleing)
                    } else {
                        context.getString(R.string.request_after_sale)
                    }
                }
            }
            OrderListActivity.WAITING_RECEIVER -> {
                mBinding.btnCallShop.apply {
                    visibility = View.VISIBLE
                    isEnabled = !itemData.isIssue
                    text = if (itemData.isIssue) {
                        context.getString(R.string.aftersaleing)
                    } else {
                        context.getString(R.string.request_after_sale)
                    }
                }
            }
            OrderListActivity.WAITING_COMMENT -> {
                mBinding.btnCallShop.apply {
                    visibility = View.VISIBLE
                    isEnabled = !itemData.isIssue
                    text = if (itemData.isIssue) {
                        context.getString(R.string.aftersaleing)
                    } else {
                        context.getString(R.string.request_after_sale)
                    }
                }
            }
            OrderListActivity.ALREADLY_CANCEL -> {
                mBinding.btnCallShop.visibility = View.GONE
            }
            OrderListActivity.ALREADLY_CLOSE -> {
                mBinding.btnCallShop.apply {
                    visibility = View.VISIBLE
                    isEnabled = !itemData.isIssue
                    text = if (itemData.isIssue) {
                        mContext.getString(R.string.aftersaleing)
                    } else {
                        mContext.getString(R.string.request_after_sale)
                    }
                }
            }
        }
        mBinding.btnCallShop.setOnClickListener {
            if (itemData.isIssue) return@setOnClickListener
            onClickAfterSale.invoke(position)
        }
    }

    lateinit var onClickAfterSale: (position: Int) -> Unit

    override fun normalViewId(viewType: Int): Int {
        return R.layout.item_order_good_item
    }
}
